using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Description:基础按钮类型
/// Author:哒先生
/// Date:2024年11月18日17:27:06
/// </summary>
public class HButton : HButtonBase
{
    
    public Text text;

    [ContextMenu("刷新样式")]
    public override void RefreshInit()
    {
        SetButtonSize(normalButtonPresettings.ButtonSize);
        image.color = normalButtonPresettings.ButtonStates[0].ButtonColor;
        image.sprite = SetButtonType(normalButtonPresettings.ButtonStates[0].ButtonType);
        text.color = normalButtonPresettings.ButtonStates[0].TextColor;
        text.fontSize = normalButtonPresettings.ButtonStates[0].fontSize;
        selectionState = SelectionState.Normal;
    }

    protected override void SetButtonState(SelectionState state)
    {
        if (buttonSelectable != null && text != null)
        {
            switch (state)
            {
                case SelectionState.Highlighted:
                    text.color = normalButtonPresettings.ButtonStates[1].TextColor;
                    text.fontSize = normalButtonPresettings.ButtonStates[1].fontSize;
                    image.color = normalButtonPresettings.ButtonStates[1].ButtonColor;
                    image.sprite = sprites[1];
                    selectionState = SelectionState.Highlighted;
                    break;
                case SelectionState.Pressed:
                    text.color = normalButtonPresettings.ButtonStates[2].TextColor;
                    text.fontSize = normalButtonPresettings.ButtonStates[2].fontSize;
                    image.color = normalButtonPresettings.ButtonStates[2].ButtonColor;
                    image.sprite = sprites[2];
                    selectionState = SelectionState.Pressed;
                    break;
                case SelectionState.Disabled:
                    text.color = normalButtonPresettings.ButtonStates[4].TextColor;
                    text.fontSize = normalButtonPresettings.ButtonStates[4].fontSize;
                    image.color = normalButtonPresettings.ButtonStates[4].ButtonColor;
                    image.sprite = sprites[4];
                    selectionState = SelectionState.Disabled;
                    break;
                case SelectionState.Normal:
                    text.color = normalButtonPresettings.ButtonStates[0].TextColor;
                    text.fontSize = normalButtonPresettings.ButtonStates[0].fontSize;
                    image.color = normalButtonPresettings.ButtonStates[0].ButtonColor;
                    image.sprite = sprites[0];
                    selectionState = SelectionState.Normal;
                    break;
                case SelectionState.Selected:
                    text.color = normalButtonPresettings.ButtonStates[3].TextColor;
                    text.fontSize = normalButtonPresettings.ButtonStates[3].fontSize;
                    image.color = normalButtonPresettings.ButtonStates[3].ButtonColor;
                    image.sprite = sprites[3];
                    selectionState = SelectionState.Selected;
                    break;

            }

        }
    }

    

}


